package com.cltolarva;

import java.io.*;
import java.util.ArrayList;

public class GetListOfFile {

	public ArrayList<String> fileName;

	public String sourceDir;

	public GetListOfFile(String sourceRoot) {
		this.fileName = new ArrayList<String>();
		this.sourceDir = sourceRoot;
		listFile(sourceRoot);
	}

	public void listFile(String tempDir) {

		File[] faFiles = new File(tempDir).listFiles();
		for (File file : faFiles) {
			if (file.getName().matches("^(.*?)")) {

				if (file.getAbsolutePath().endsWith(".java")) {
					
					this.fileName.add(file.getAbsolutePath());
				}

			}
			if (file.isDirectory()) {
				listFile(file.getAbsolutePath());
			}
		}
	}
	
	public String getImports(){
		
		StringBuilder str=new StringBuilder();
		char cDot = '\u002E';
		char cBack = '\\';
		
		for(int i=0;i<this.fileName.size();i++){
			
			String temp = this.fileName.get(i).replace(cBack, cDot);
			
			str.append("\t");
			str.append("import ");
			str.append(temp.substring((sourceDir.length()+1),(temp.length()-5)));
			str.append(";");
			str.append("\n");
		}
		
		return str.toString();
	}
	
	/*public static void main(String args[]) {
		GetListOfFile lf=new GetListOfFile("F:\\Gothenburg University\\MSc Thesis\\Runtime Verification\\LARVA\\LARVA complete package\\Java demo systems\\bank system");
		
		System.out.print(lf.getImports());
	}*/
}
